﻿using SuperMap.Data;
using SuperMap.Realspace;
using System;
using System.Collections.Generic;
using WeifenLuo.WinFormsUI.Docking;
using Ycjw.PipeLine.Map.Basic.Conditions;
using Ycjw.PipeLine.Map.Basic.SuperMap;

namespace Ycjw.PipeLine.Map.Tools.Conditions
{
    class GKSearcher : ConditionPanel
    {
        private Sunny.UI.UIGroupBox uiGroupBoxGK;
        private Sunny.UI.UIGroupBox uiGroupBox2;
        private Sunny.UI.UILabel uiLabel2;
        private Sunny.UI.UIDoubleUpDown uiDoubleUpDownbyGD;
        private Sunny.UI.UIDoubleUpDown uiDoubleUpDownbyKD;
        private Sunny.UI.UILabel uiLabel1;
        private LayerWithDataListPanel LayerWithDataListPanel;
        public override string ConditionPanelName { get => base.ConditionPanelName; set => base.ConditionPanelName = value; }

        public GKSearcher() : base()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            LayerWithDataListPanel = new LayerWithDataListPanel()
            {
                Dock = System.Windows.Forms.DockStyle.Fill
            };
            Scene scene = this.Scene;
            if (scene == null) return;
            LayerWithDataListPanel.Init(scene);
            //LayerWithDataListPanel.LoadToVector();   
            var types = new List<DatasetType>()
            {
                DatasetType.Line,
                DatasetType.Line3D,
                DatasetType.Network,
                DatasetType.Network3D
            };
            LayerWithDataListPanel.LoadTo(types);
            this.uiGroupBoxGK.Controls.Add(LayerWithDataListPanel);
            this.uiGroupBoxGK.Width = this.Width / 2;
        }


        public override bool ConditionValid()
        {
            var dataset = LayerWithDataListPanel.SelectLayer3DDataset;
            if (dataset == null)
            {
                Sunny.UI.UIMessageTip.ShowError("选择的图层不是矢量图层");
                return false;
            }
            return base.ConditionValid();
        }


        public override object Do(DockPanel dockPanel = null)
        {
            var dataset = LayerWithDataListPanel.SelectLayer3DDataset;
            if (dataset == null)
            {
                Sunny.UI.UIMessageTip.ShowError("选择的图层不是矢量图层");
                return null;
            }
            var dataSetVector = dataset.Dataset as SuperMap.Data.DatasetVector;
            bool hasGJField = false;

            for (int i = 0; i < dataSetVector.FieldInfos.Count; i++)
            {
                if (dataSetVector.FieldInfos[i].Name == "SSPIPEHEIGHT" || dataSetVector.FieldInfos[i].Name == "SSPIPEWIDTH")//SSPIPEWIDTH(宽)SSPIPEHEIGHT(高) 
                {
                    hasGJField = true;
                    break;
                }
            }

            if (!hasGJField)
            {
                Sunny.UI.UIMessageTip.ShowError("选择的图层没有宽度或者高度信息");
                return null;
            }
            DatasetVectorEx dvEx = new DatasetVectorEx(dataSetVector.Name)
            {
                DatasetVector = dataSetVector
            };

            return dvEx.Query("SSPIPEHEIGHT >=" + this.uiDoubleUpDownbyGD.Value + " and SSPIPEWIDTH >=" + this.uiDoubleUpDownbyKD.Value);
        }

        public override SortedDictionary<string, object> SetConditions()
        {
            return new SortedDictionary<string, object>();
        }

        private void InitializeComponent()
        {
            this.uiGroupBoxGK = new Sunny.UI.UIGroupBox();
            this.uiGroupBox2 = new Sunny.UI.UIGroupBox();
            this.uiDoubleUpDownbyKD = new Sunny.UI.UIDoubleUpDown();
            this.uiDoubleUpDownbyGD = new Sunny.UI.UIDoubleUpDown();
            this.uiLabel2 = new Sunny.UI.UILabel();
            this.uiLabel1 = new Sunny.UI.UILabel();
            this.uiGroupBox2.SuspendLayout();
            this.SuspendLayout();
            // 
            // uiGroupBoxGK
            // 
            this.uiGroupBoxGK.Dock = System.Windows.Forms.DockStyle.Left;
            this.uiGroupBoxGK.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiGroupBoxGK.Location = new System.Drawing.Point(0, 0);
            this.uiGroupBoxGK.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiGroupBoxGK.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiGroupBoxGK.Name = "uiGroupBoxGK";
            this.uiGroupBoxGK.Padding = new System.Windows.Forms.Padding(0, 32, 0, 0);
            this.uiGroupBoxGK.Size = new System.Drawing.Size(241, 340);
            this.uiGroupBoxGK.TabIndex = 0;
            this.uiGroupBoxGK.Text = "查询类型";
            // 
            // uiGroupBox2
            // 
            this.uiGroupBox2.Controls.Add(this.uiDoubleUpDownbyKD);
            this.uiGroupBox2.Controls.Add(this.uiDoubleUpDownbyGD);
            this.uiGroupBox2.Controls.Add(this.uiLabel2);
            this.uiGroupBox2.Controls.Add(this.uiLabel1);
            this.uiGroupBox2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.uiGroupBox2.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiGroupBox2.Location = new System.Drawing.Point(241, 0);
            this.uiGroupBox2.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiGroupBox2.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiGroupBox2.Name = "uiGroupBox2";
            this.uiGroupBox2.Padding = new System.Windows.Forms.Padding(0, 32, 0, 0);
            this.uiGroupBox2.Size = new System.Drawing.Size(267, 340);
            this.uiGroupBox2.TabIndex = 0;
            this.uiGroupBox2.Text = "查询参数";
            // 
            // uiDoubleUpDownbyKD
            // 
            this.uiDoubleUpDownbyKD.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiDoubleUpDownbyKD.Location = new System.Drawing.Point(78, 32);
            this.uiDoubleUpDownbyKD.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiDoubleUpDownbyKD.MinimumSize = new System.Drawing.Size(100, 0);
            this.uiDoubleUpDownbyKD.Name = "uiDoubleUpDownbyKD";
            this.uiDoubleUpDownbyKD.Size = new System.Drawing.Size(136, 29);
            this.uiDoubleUpDownbyKD.Step = 1D;
            this.uiDoubleUpDownbyKD.TabIndex = 4;
            this.uiDoubleUpDownbyKD.Text = null;
            this.uiDoubleUpDownbyKD.Value = 0D;
            // 
            // uiDoubleUpDownbyGD
            // 
            this.uiDoubleUpDownbyGD.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiDoubleUpDownbyGD.Location = new System.Drawing.Point(79, 73);
            this.uiDoubleUpDownbyGD.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiDoubleUpDownbyGD.MinimumSize = new System.Drawing.Size(100, 0);
            this.uiDoubleUpDownbyGD.Name = "uiDoubleUpDownbyGD";
            this.uiDoubleUpDownbyGD.Size = new System.Drawing.Size(136, 29);
            this.uiDoubleUpDownbyGD.Step = 1D;
            this.uiDoubleUpDownbyGD.TabIndex = 3;
            this.uiDoubleUpDownbyGD.Text = null;
            this.uiDoubleUpDownbyGD.Value = 0D;
            // 
            // uiLabel2
            // 
            this.uiLabel2.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiLabel2.Location = new System.Drawing.Point(7, 73);
            this.uiLabel2.Name = "uiLabel2";
            this.uiLabel2.Size = new System.Drawing.Size(65, 29);
            this.uiLabel2.TabIndex = 2;
            this.uiLabel2.Text = "高度：";
            this.uiLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // uiLabel1
            // 
            this.uiLabel1.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiLabel1.Location = new System.Drawing.Point(7, 32);
            this.uiLabel1.Name = "uiLabel1";
            this.uiLabel1.Size = new System.Drawing.Size(64, 29);
            this.uiLabel1.TabIndex = 0;
            this.uiLabel1.Text = "宽度：";
            this.uiLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // GKSearcher
            // 
            this.Controls.Add(this.uiGroupBox2);
            this.Controls.Add(this.uiGroupBoxGK);
            this.Name = "GKSearcher";
            this.Size = new System.Drawing.Size(508, 340);
            this.uiGroupBox2.ResumeLayout(false);
            this.ResumeLayout(false);

        }
    }
}
